package cn.xiaoyu.su.service.impl;

import cn.xiaoyu.su.interceptor.LoginInterceptor;
import cn.xiaoyu.su.manager.DomainManager;
import cn.xiaoyu.su.model.DomainDO;
import cn.xiaoyu.su.mapper.DomainMapper;
import cn.xiaoyu.su.service.DomainService;
import cn.xiaoyu.su.vo.DomainVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ⼆当家⼩D
 * @since 2022-12-08
 */
@Service
@Slf4j
public class DomainServiceImpl implements DomainService {

    @Autowired
    private DomainManager domainManager;
    /**
     * 列举全部可用域名
     * @return
     */
    @Override
    public List<DomainVO> listAll() {

        Long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();

        List<DomainDO> customDomainList = domainManager.listCustomDomain(accountNo);

        List<DomainDO> officialDomainList = domainManager.listOfficialDomain();

        customDomainList.addAll(officialDomainList);

        return customDomainList.stream().map(obj -> beanProcess(obj)).collect(Collectors.toList());
    }

    private DomainVO beanProcess(DomainDO domainDO) {
        DomainVO domainVO = new DomainVO();
        BeanUtils.copyProperties(domainDO,domainVO);
        return domainVO;
    }
}
